var index=0;
var _name;
/**
* 
* @param $id  将要绑定的html id
* @param data 统计数据
* @param name 标题
* @param swfPath swf文件路径
* @param isResize 是否手动调整图标大小
* @param panelW 绑定标签的宽度
* @param panelH 绑定标签的长度
* @param chartW 图标宽度
* @param charH 图标高度
* @param isClearBorder 是否要去掉标签边框
* @param paddingLeft 图表内边距
* @returns {Number}
*/
function statistic($id,data,name,swfPath,isResize,panelW,panelH,chartW,charH,isClearBorder,paddingLeft){
    initStastic($id,isResize,panelW,panelH,isClearBorder,paddingLeft);
    var param=getStasticParam(name,getStasticData(data));
    drawStatistic(param,$id,swfPath,isResize,chartW,charH);
    
    _name =name;
}

function getStasticParam(name,data){
    var param={"chart": {
                            "caption": name,//标题
                            "numberprefix": "",//数字前缀
                            "plotgradientcolor": "",//渐变颜色，6位16进制颜色值
                            "bgcolor": "FFFFFF",//图表背景色
                            "showalternatehgridcolor": "0",//是否在横向网格带交替的颜色
                            "canvasborderthickness": "1",//画布边框厚度
                            "captionpadding": "30",//标题内边距
                            "use3dlighting": "0",//是否3d
                            "showshadow": "1",//是否显示阴影
                            "showBorder": "0",//是否显示图表边框
                            "numberscalevalue": "1000,1000,1000",
                            "palettecolors": "#f8bd19,#e44a00,#008ee4,#33bdda,#6baa01,#583e78",
                            "baseFont":"微软雅黑",//字体
                            "baseFontSize":"14",//字体大小
                            "baseFontColor":"333"//字体颜色
                    },
                "data": data
            };
            
            return param;
}

function getStasticData(data){ 
    var rData=[];
    for(var i in data){
        var objElement={ "label": data[i].key, "value": data[i].value, "issliced": "0" };
        rData.push(objElement);
    }
    return rData;
}

function drawStatistic(param,id,swfPath,isResize,chartW,charH){
    var _chartW="300";
    var _charH="300";
    if(isResize){
        _chartW=chartW;
        _charH=charH;
    }
	_chartW="100%";
    _charH="100%";
    //swfPath= "static/js/charts/Pie2D.swf"
	FusionCharts.setCurrentRenderer('javascript');
	
	
    var myChart = new FusionCharts(swfPath,"analysisCount"+index, _chartW,_charH, "0","1" );
    myChart.setJSONData(param);
    myChart.render(id);
	
    index++;
}

function initStastic($id,isResize,panelW,panelH,isClearBorder,paddingLeft){
    var _relative="position:relative";
    var _border="border: 1px solid #DDD;";
    var _panelW="width: 390px;";
    var _panelH="height: 303px;";
    var _paddingLeft="padding-left: 0px;";
    if(isResize){
        _panelW="width: "+panelW+"px;";
        _panelH="height: "+panelH+"px;";
        _paddingLeft="padding-left: "+paddingLeft+"px;";
    }
    
    if(isClearBorder){
        _border="";
    }
    document.getElementById($id).style.cssText=_border+_panelW+_panelH+_paddingLeft+_relative;
}
/**
* 重新设置图表边框
* @param $id 绑定标签id
* @param width  设置宽度
* @param height 设置高度
* @param top  设置上面的距离
* @param left 设置左边距离
* @returns {Number}
*/
function reDefineBorder($id,width,height,top,left,titleTop){
    var newNode=document.createElement("div");
    newNode.style.cssText="position: absolute;width:"+width+"px;height:"+height+"px;border:1px solid #DDD;top: "+top+"px;left: "+left+"px;";
    document.getElementById($id).appendChild(newNode);
    
    if(_name.replace(/(^\s*)|(\s*$)/g,"") == ''){
        var nameNode=document.createElement("div");
        nameNode.style.cssText='position: absolute;width:80px;height:30px;  top: '+titleTop+'px;  left: 50%;font-weight: bold;';
        var textNode=document.createTextNode('name');
        nameNode.appendChild(textNode);
        document.getElementById($id).appendChild(newNode);
        document.getElementById($id).appendChild(nameNode);
    }
}